/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.dconnection.SQLServerConnect;
import qlvbdq.dto.CTBCDoanhThuDTO;

/**
 *
 * @author tuan
 */
public class CTBaoCaoDoanhThuDAO {
    
    public ArrayList<CTBCDoanhThuDTO> getCTBCDoanhThuByMaBCDoanhThu(String MaBCDoanhThu) throws SQLException {
        ArrayList<CTBCDoanhThuDTO> listCTPDV = new ArrayList<>();
        Object[] objs = { MaBCDoanhThu };
        CTBCDoanhThuDTO ctBCDoanhThu = new CTBCDoanhThuDTO();
        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTBaoCaoDoanhThuFromDataBase( ? )", objs);
        while (rs.next()) {
            ctBCDoanhThu.setMaBCDT(rs.getString("MABCDT"));
            ctBCDoanhThu.setMaSP(rs.getString("MASP"));
            ctBCDoanhThu.setDoanhThu(rs.getLong("DOANHTHU"));
            ctBCDoanhThu.setTyLe(rs.getInt("TYLE"));
            listCTPDV.add(ctBCDoanhThu);
        }
        return listCTPDV;
    }
    
//    public ArrayList<CTBCDoanhThuDTO> getCTBCDoanhThuByMaBaoCaoAndMaSP(String MaBCDoanhThu, String MaSP) throws SQLException {
//        ArrayList<CTBCDoanhThuDTO> listCTPDV = new ArrayList<>();
//        Object[] objs = { MaBCDoanhThu, MaSP };
//        CTBCDoanhThuDTO ctBCDoanhThu = new CTBCDoanhThuDTO();
//        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTBCDoanhThuByMaDVFromDatabase( ?, ? )", objs);
//        while (rs.next()) {
//            ctBCDoanhThu.setMaBCDoanhThu(rs.getString("MABAOCAOTON"));
//            ctBCDoanhThu.setMaSP(rs.getString("MASP"));
//            ctBCDoanhThu.setSoLuongBan(rs.getInt("SOLUONGBAN"));
//            ctBCDoanhThu.setSoLuongMua(rs.getInt("SOLUONGMUA"));
//            ctBCDoanhThu.setTonDauKy(rs.getInt("TONDAUKY"));
//            ctBCDoanhThu.setTonCuoiky(rs.getInt("TONCUOIKY"));
//            listCTPDV.add(ctBCDoanhThu);
//        }
//        return listCTPDV;
//    }
    
    public int insertCTBCDoanhThu(CTBCDoanhThuDTO ctBCDoanhThu) {
        Object[] objs = { ctBCDoanhThu.getMaBCDT(), ctBCDoanhThu.getMaSP(), ctBCDoanhThu.getDoanhThu(), 
                            ctBCDoanhThu.getTyLe()};
        return SQLServerConnect.getInstance().updateDataToDatabase("InsertCTBaoCaoDoanhThuToDataBase(?, ?, ?, ?)", objs);
    }
    
   //xoa toan bo chi tiet cua BCDoanhThu do
    public int deleteCTBCDoanhThuByMaBaoCao(CTBCDoanhThuDTO ctBCDoanhThu) {
        Object[] objs = { ctBCDoanhThu.getMaBCDT()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteAllCTBaoCaoDoanhThuOfBCDTFromDataBase(?)", objs);
    }
    
}
